/*
 *    Copyright 2008-2009 The PoCo Team
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package com.asemantics.poco.query;

import java.net.MalformedURLException;
import java.net.URL;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

/**
 * 
 * @author Simone Tripodi
 * @version $Id: PathBuilder.java 223 2009-12-19 21:32:32Z simone.tripodi@gmail.com $
 */
@EqualsAndHashCode
@ToString
public final class PathBuilder {

    private final static String ALL = "@me/@all";

    private final static String SELF = "@me/@self";

    @Getter
    private final URL allURL;

    @Getter
    private final URL selfURL;

    public PathBuilder(URL baseURL) throws MalformedURLException {
        this.allURL = new URL(baseURL, ALL);
        this.selfURL = new URL(baseURL, SELF);
    }

    public URL getUserURL(String id) throws MalformedURLException {
        if (id.charAt(0) == '/') {
            return new URL(this.allURL, id);
        }
        return new URL(this.allURL, '/' + id);
    }

}
